package controller

import (
	"simple-mail/model"
	"simple-mail/serializer"
	"simple-mail/service"

	"github.com/gin-gonic/gin"
)

// SendMail 发送邮件
func SendMail(c *gin.Context) {
	var request model.SendMailRequest
	err := c.ShouldBindJSON(&request)
	if nil != err || !request.Check() {
		serializer.ResponseParamErr(c)
		return
	}
	var mailService service.MailService
	sendSuccess, toUserMsg := mailService.SendMail(request, c.ClientIP())
	if !sendSuccess {
		serializer.ResponseServerErr(c, toUserMsg)
	} else {
		serializer.ResponseOk(c)
	}
}
